home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / GameboyDev / GBDK / include / gb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-29  |  5.8 KB  |  345 lines

  1. #ifndef _GB_H
  2. #define _GB_H
  3.  
  4. #include <types.h>
  5. #include <hardware.h>
  6. #include <sgb.h>
  7. #include <cgb.h>
  8.  
  9. /* Joypad bits */
  10.  
  11. #define    J_START      0x80U
  12. #define    J_SELECT     0x40U
  13. #define    J_B          0x20U
  14. #define    J_A          0x10U
  15. #define    J_DOWN       0x08U
  16. #define    J_UP         0x04U
  17. #define    J_LEFT       0x02U
  18. #define    J_RIGHT      0x01U
  19.  
  20. /* Modes */
  21.  
  22. #define    M_DRAWING    0x01U
  23. #define    M_TEXT_OUT   0x02U
  24. #define    M_TEXT_INOUT 0x03U
  25. /* Set this in addition to the others to disable scrolling 
  26.    If scrolling is disabled, the cursor returns to (0,0) */
  27. #define M_NO_SCROLL  0x04U
  28. /* Set this to disable \n interpretation */
  29. #define M_NO_INTERP  0x08U
  30.  
  31. /* Sprite properties bits */
  32.  
  33. #define S_PALETTE    0x10U
  34. #define S_FLIPX      0x20U
  35. #define S_FLIPY      0x40U
  36. #define S_PRIORITY   0x80U
  37.  
  38. /* Interrupt flags */
  39.  
  40. #define VBL_IFLAG    0x01U
  41. #define LCD_IFLAG    0x02U
  42. #define TIM_IFLAG    0x04U
  43. #define SIO_IFLAG    0x08U
  44. #define JOY_IFLAG    0x10U
  45.  
  46. /* Limits */
  47.  
  48. #define SCREENWIDTH  0xA0U
  49. #define SCREENHEIGHT 0x90U
  50. #define MINWNDPOSX   0x07U
  51. #define MINWNDPOSY   0x00U
  52. #define MAXWNDPOSX   0xA6U
  53. #define MAXWNDPOSY   0x8FU
  54.  
  55. /* ************************************************************ */
  56.  
  57. /*
  58.  * Interrupt handlers
  59.  */
  60. typedef void (*int_handler)(void);
  61.  
  62. void
  63. add_VBL(int_handler h);
  64.  
  65. void
  66. add_LCD(int_handler h);
  67.  
  68. void
  69. add_TIM(int_handler h);
  70.  
  71. void
  72. add_SIO(int_handler h);
  73.  
  74. void
  75. add_JOY(int_handler h);
  76.  
  77. /* ************************************************************ */
  78.  
  79. /* Set the current mode - one of M_* defined above */
  80. void
  81.     mode(UBYTE m);
  82.  
  83. /* Returns the current mode */
  84. UBYTE
  85.     get_mode(void);
  86.  
  87. /* GB type (GB, PGB, CGB) */
  88. extern UBYTE _cpu;
  89.  
  90. #define DMG_TYPE 0x01 /* Original GB or Super GB */
  91. #define MGB_TYPE 0xFF /* Pocket GB or Super GB 2 */
  92. #define CGB_TYPE 0x11 /* Color GB */
  93.  
  94. extern UWORD sys_time;    /* Time in VBL periods (60Hz) */
  95.  
  96. /* ************************************************************ */
  97.  
  98. void
  99. send_byte(void);
  100. /* Send byte in _io_out to the serial port */
  101.  
  102. void
  103. receive_byte(void);
  104. /* Receive byte from the serial port in _io_in */
  105.  
  106. extern UBYTE _io_status;
  107. extern UBYTE _io_in;
  108. extern UBYTE _io_out;
  109.  
  110. /* Status codes */
  111. #define IO_IDLE        0x00U        /* IO is completed */
  112. #define IO_SENDING    0x01U        /* Sending data */
  113. #define IO_RECEIVING    0x02U        /* Receiving data */
  114. #define IO_ERROR    0x04U        /* Error */
  115.  
  116. /* ************************************************************ */
  117.  
  118. /* Multiple banks */
  119.  
  120. /* MBC1 */
  121. #define SWITCH_ROM_MBC1(b) \
  122.   *(unsigned char *)0x2000 = (b)
  123.  
  124. #define SWITCH_RAM_MBC1(b) \
  125.   *(unsigned char *)0x4000 = (b)
  126.  
  127. #define ENABLE_RAM_MBC1 \
  128.   *(unsigned char *)0x0000 = 0x0A
  129.  
  130. #define DISABLE_RAM_MBC1 \
  131.   *(unsigned char *)0x0000 = 0x00
  132.  
  133. /* MBC5 */
  134. #define SWITCH_ROM_MBC5(b) \
  135.   *(unsigned char *)0x2000 = (b)&0xFF; \
  136.   *(unsigned char *)0x3000 = (b)>>8
  137.  
  138. #define SWITCH_RAM_MBC5(b) \
  139.   *(unsigned char *)0x4000 = (b)
  140.  
  141. #define ENABLE_RAM_MBC5 \
  142.   *(unsigned char *)0x0000 = 0x0A
  143.  
  144. #define DISABLE_RAM_MBC5 \
  145.   *(unsigned char *)0x0000 = 0x00
  146.  
  147. /* ************************************************************ */
  148.  
  149. void
  150. delay(UWORD d);
  151.  
  152. /* ************************************************************ */
  153.  
  154. UBYTE
  155. joypad(void);
  156.  
  157. UBYTE
  158. waitpad(UBYTE mask);
  159.  
  160. void
  161. waitpadup(void);
  162.  
  163. /* ************************************************************ */
  164.  
  165. void
  166. enable_interrupts(void);
  167.  
  168. void
  169. disable_interrupts(void);
  170.  
  171. void
  172. set_interrupts(UBYTE flags);
  173.  
  174. void
  175. reset(void);
  176.  
  177. void
  178. wait_vbl_done(void);
  179.  
  180. void
  181. display_off(void);
  182.  
  183. /* ************************************************************ */
  184.  
  185. void
  186. hiramcpy(UBYTE dst,
  187.      const void *src,
  188.      UBYTE n);
  189.  
  190. /* ************************************************************ */
  191.  
  192. #define DISPLAY_ON \
  193.   LCDC_REG|=0x80U
  194.  
  195. #define DISPLAY_OFF \
  196.   display_off();
  197.  
  198. #define SHOW_BKG \
  199.   LCDC_REG|=0x01U
  200.  
  201. #define HIDE_BKG \
  202.   LCDC_REG&=0xFEU
  203.  
  204. #define SHOW_WIN \
  205.   LCDC_REG|=0x20U
  206.  
  207. #define HIDE_WIN \
  208.   LCDC_REG&=0xDFU
  209.  
  210. #define SHOW_SPRITES \
  211.   LCDC_REG|=0x02U
  212.  
  213. #define HIDE_SPRITES \
  214.   LCDC_REG&=0xFDU
  215.  
  216. #define SPRITES_8x16 \
  217.   LCDC_REG|=0x04U
  218.  
  219. #define SPRITES_8x8 \
  220.   LCDC_REG&=0xFBU
  221.  
  222. /* ************************************************************ */
  223.  
  224. void
  225. set_bkg_data(UBYTE first_tile,
  226.          UBYTE nb_tiles,
  227.          unsigned char *data);
  228.  
  229. void
  230. set_bkg_tiles(UBYTE x,
  231.           UBYTE y,
  232.           UBYTE w,
  233.           UBYTE h,
  234.           unsigned char *tiles);
  235.  
  236. void
  237. get_bkg_tiles(UBYTE x,
  238.           UBYTE y,
  239.           UBYTE w,
  240.           UBYTE h,
  241.           unsigned char *tiles);
  242.  
  243. void
  244. move_bkg(UBYTE x,
  245.      UBYTE y);
  246.  
  247. void
  248. scroll_bkg(BYTE x,
  249.        BYTE y);
  250.  
  251. /* ************************************************************ */
  252.  
  253. void
  254. set_win_data(UBYTE first_tile,
  255.          UBYTE nb_tiles,
  256.          unsigned char *data);
  257.  
  258. void
  259. set_win_tiles(UBYTE x,
  260.           UBYTE y,
  261.           UBYTE w,
  262.           UBYTE h,
  263.           unsigned char *tiles);
  264.  
  265. void
  266. get_win_tiles(UBYTE x,
  267.           UBYTE y,
  268.           UBYTE w,
  269.           UBYTE h,
  270.           unsigned char *tiles);
  271.  
  272. void
  273. move_win(UBYTE x,
  274.      UBYTE y);
  275.  
  276. void
  277. scroll_win(BYTE x,
  278.        BYTE y);
  279.  
  280. /* ************************************************************ */
  281.  
  282. void
  283. set_sprite_data(UBYTE first_tile,
  284.         UBYTE nb_tiles,
  285.         unsigned char *data);
  286.  
  287. void
  288. get_sprite_data(UBYTE first_tile,
  289.         UBYTE nb_tiles,
  290.         unsigned char *data);
  291.  
  292. void
  293. set_sprite_tile(UBYTE nb,
  294.         UBYTE tile);
  295.  
  296. UBYTE
  297. get_sprite_tile(UBYTE nb);
  298.  
  299. void
  300. set_sprite_prop(UBYTE nb,
  301.         UBYTE prop);
  302.  
  303. UBYTE
  304. get_sprite_prop(UBYTE nb);
  305.  
  306. void
  307. move_sprite(UBYTE nb,
  308.         UBYTE x,
  309.         UBYTE y);
  310.  
  311. void
  312. scroll_sprite(BYTE nb,
  313.           BYTE x,
  314.           BYTE y);
  315.  
  316. /* ************************************************************ */
  317.  
  318. void
  319. set_data(unsigned char *vram_addr,
  320.      unsigned char *data,
  321.      UWORD len);
  322.  
  323. void
  324. get_data(unsigned char *data,
  325.      unsigned char *vram_addr,
  326.      UWORD len);
  327.  
  328. void
  329. set_tiles(UBYTE x,
  330.       UBYTE y,
  331.       UBYTE w,
  332.       UBYTE h,
  333.       unsigned char *vram_addr,
  334.       unsigned char *tiles);
  335.  
  336. void
  337. get_tiles(UBYTE x,
  338.       UBYTE y,
  339.       UBYTE w,
  340.       UBYTE h,
  341.       unsigned char *tiles,
  342.       unsigned char *vram_addr);
  343.  
  344. #endif /* _GB_H */
  345.